/***********************************************************************
 * <:copyright-BRCM:2007-2013:proprietary:standard
 * 
 *    Copyright (c) 2007-2013 Broadcom 
 *    All Rights Reserved
 * 
 *  This program is the proprietary software of Broadcom and/or its
 *  licensors, and may only be used, duplicated, modified or distributed pursuant
 *  to the terms and conditions of a separate, written license agreement executed
 *  between you and Broadcom (an "Authorized License").  Except as set forth in
 *  an Authorized License, Broadcom grants no license (express or implied), right
 *  to use, or waiver of any kind with respect to the Software, and Broadcom
 *  expressly reserves all rights in and to the Software and all intellectual
 *  property rights therein.  IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE
 *  NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY
 *  BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE.
 * 
 *  Except as expressly set forth in the Authorized License,
 * 
 *  1. This program, including its structure, sequence and organization,
 *     constitutes the valuable trade secrets of Broadcom, and you shall use
 *     all reasonable efforts to protect the confidentiality thereof, and to
 *     use this information only in connection with your use of Broadcom
 *     integrated circuit products.
 * 
 *  2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
 *     AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
 *     WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
 *     RESPECT TO THE SOFTWARE.  BROADCOM SPECIFICALLY DISCLAIMS ANY AND
 *     ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT,
 *     FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
 *     COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE
 *     TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF USE OR
 *     PERFORMANCE OF THE SOFTWARE.
 * 
 *  3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR
 *     ITS LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL,
 *     INDIRECT, OR EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY
 *     WAY RELATING TO YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN
 *     IF BROADCOM HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES;
 *     OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE
 *     SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE LIMITATIONS
 *     SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF ANY
 *     LIMITED REMEDY.
 * :> *
 * $Change: 109793 $
 ***********************************************************************/

//#include "cms.h"
#include <stdio.h>
#include <string.h>

#define ENABLE_PC_DEBUG 1

#define CMSRET_SUCCESS 0
#define TRUE 1
#define FALSE 0
#define INFORM_EVENT_VALUE_CHANGE 4

//#define cmsLog_error(fmt, arg...)  printf("%s.%u: " fmt "\n", __FUNCTION__, __LINE__, ##arg)
#define cmsLog_error(fmt, arg...)  printf(fmt "\n", ##arg)

typedef unsigned char UBOOL8;
typedef unsigned char UINT8;
typedef unsigned short UINT16;
typedef unsigned int UINT32;
typedef int SINT32;
typedef int CmsRet;

typedef enum {
   eACSNeverContacted=0,
   eACSContacted,
   eACSInformed,
   eACSUpload,
   eACSDownloadReboot,
   eACSSetValueReboot,
   eACSAddObjectReboot,
   eACSDelObjectReboot,
   eACSRPCReboot
} eInformState;

typedef struct
{
   UINT32 sec;   /**< Number of seconds since some arbitrary point. */
   UINT32 nsec;  /**< Number of nanoseconds since some arbitrary point. */
} CmsTimestamp;

typedef struct ACSState {
    int         acsEnable;
    char        *acsURL;        /* URL of ACS */
    char        *acsUser;
    char        *acsPwd;
    time_t      informTime;     /* next ACS inform Time */
    time_t      informInterval; /* inform interval */
    int         informEnable;   /* True if inform to be performed*/
    int         maxEnvelopes;   /* Number of max env returned in inform response*/
    int         holdRequests;   /* hold request to ACS if true */
    int         noMoreRequests; /* don't send any more Req to ACS */
    //RpcMethods  acsRpcMethods;  /* methods from GetRPCMethods response*/
    char        *rebootCommandKey; /* key for reboot command key */
    char        *downloadCommandKey;    /* key for download cmd*/
    int         noneConnReqAuth;  /* no connection request authentication*/
    char        *boundIfName;     /* name of interface which tr69c works on, see description in data model */
    char        *connReqURL;
    char        *connReqIpAddr; /* IP address part of connReqURL -- part of the inform msg */
    char        *connReqIpAddrFullPath; /* full path to the parameter that holds the connReqIpAddr, part of the inform msg */
    char        *connReqPath;   /* path part of connReqURL -- used by listener.c */
    char        *connReqUser;
    char        *connReqPwd;
    unsigned short connReqPort;
    char        *kickURL;
    char        upgradesManaged;
    char        *provisioningCode;
    int         retryCount;     /* reset on each ACS response*/
    int         fault;          /* last operation fault code */
    int         dlFaultStatus;  /* download fault status */
    char        *dlFaultMsg;    /* download fault message */
    time_t      startDLTime;    /* start download time */
    time_t      endDLTime;      /* complete download time*/
    char        *scheduleInformCommandKey;    /* key for scheduleInform*/
    char        *manufacturer;      /**< from deviceInfo */
    char        *manufacturerOUI;   /**< from deviceInfo */
    char        *productClass;      /**< from deviceInfo */
    char        *serialNumber;      /**< from deviceInfo */
    //struct ChangeDuStateOpReqInfo *duStateOpList;  /**< each DU Operatation save, opResultStruct can be built later  */
    char        *duStateChangeCommandKey; /*  command key */
    unsigned    currentDuChangeReqId;
    unsigned    pendingDuReq;
    int         dataModel;        /* the data model which client communicates with ACS: TR98, TR181 */
    int         cwmpVersion;      /* default is v1.2, but can revert back to 1.0 */
    char        *redirectURL;     /* redirect ACS URL */
} ACSState;

/*! \brief STUN information
 */
typedef struct  
{
  char*           UDPConnReqAddress; /**< read-only */
  UBOOL8          NATDetected; /**< read-only */
  UINT32          AddressNotificationLimit;
  UBOOL8          Enable;
  char*           ServerAddress; 
  UINT32          ServerPort;
  char*           Username;   
  char*           Password;   
  SINT32          MaxKeepAlivePeriod;
  UINT32          MinKeepAlivePeriod;
  UINT32          ClientPort; /**< internal data */
  UINT32          ClientRecvTimeOut; /**< internal data */
  UINT32          ClientSendRetryTimes; /**< internal data */
  UINT32          ClientTimeWait;  /**< internal data */
  UBOOL8          UDPConnReqAddressIsChanged; /**< internal data */
} STUNData;

//CmsRet stunCms_getCPELanIPAddr(int* ip);
//CmsRet stunCms_updateParameters(STUNData* stun_data);
//CmsRet stunCms_getSTUNConfig(STUNData* stun_data);
//CmsRet stunCms_configChanged(STUNData* stun_data);
//CmsRet stunCms_isActiveNotificationEnabled(char* paramName, UBOOL8* enabled);

